package util

// InStringArray
func InStringArray(checkKey string, checkArray []string) bool {
	for _, key := range checkArray {
		if key == checkKey {
			return true
		}
	}
	return false
}

// Int32BoolMap
type Int32BoolMap map[uint32]bool

// Int64BoolMap
type Int64BoolMap map[uint64]bool

// StringBoolMap
type StringBoolMap map[string]bool

// IntInterfaceMap
type IntStringMap map[int]string

// GetKeys
func (m Int32BoolMap) GetKeys() (keys []uint32) {
	keys = make([]uint32, 0, len(m))
	for key := range m {
		keys = append(keys, key)
	}
	return
}

// GetKeys
func (m Int64BoolMap) GetKeys() (keys []uint64) {
	keys = make([]uint64, 0, len(m))
	for key := range m {
		keys = append(keys, key)
	}
	return
}

// GetKeys
func (m StringBoolMap) GetKeys() (keys []string) {
	keys = make([]string, 0, len(m))
	for key := range m {
		keys = append(keys, key)
	}
	return
}

// GetKeys
func (m IntStringMap) GetKeys() (keys []int) {
	keys = make([]int, 0, len(m))
	for key := range m {
		keys = append(keys, key)
	}
	return
}

// GetUniqueSlice
func GetUniqueSlice(t []int) []int {
	d := make(map[int]bool)
	r := make([]int, 0)
	for _, i := range t {
		if !d[i] {
			d[i] = true
			r = append(r, i)
		}
	}
	return r
}

func FormatIntArrayToInt64Array(in []int) (out []uint64) {
	for _, i := range in {
		out = append(out, uint64(i))
	}
	return
}

func FormatInt64ArrayToIntArray(in []uint64) (out []int) {
	for _, i := range in {
		out = append(out, int(i))
	}
	return
}

func GetStringWithinLength(input string, length int) string {
	if len(input) > length {
		return input[0:length]
	} else {
		return input
	}
}
